package control;
import model.Model;
import utils.DebugHandler;
import utils.Splash;
import view.View;

/**
 * LTNG entry point.
 */
public class Main {

    private static View v;
    @SuppressWarnings("unused")
    private static Model m;
    public static Settings s;

    public static void main(String[] args) {
        if(args.length > 0){
            parseArgs(args);
        }

        Splash t = new Splash();
        t.start();
        while(t.isAlive() && !t.isLooping()){
            t.getName(); //Only called to make the loop work in runtime (else the optimizing process will remove it????).
        }
        System.out.println("1 Loading Settings");
        loadSettings();
        System.out.println("2 Creating View");
        v = new View();
        System.out.println("3 Creating Model");
        m = new Model();
        System.out.println("4 Interrupting Splash");
        t.interrupt();
        System.out.println("5 Making GUI visible");
        v.setVisible(true);
        v.toFront();
        System.gc(); //Collect the garbage and we're in business.
    }

    private static void parseArgs(String[] args){
        for(int i = 0; i < args.length; i++){
            if(args[i].equals("-d"))
                DebugHandler.setEnabled(true);
            if(args[i].equals("-io"))
                DebugHandler.setIO(true);
        }
    }

    private static void loadSettings(){
        System.out.println("1.1 Initializing Settings");
        s = new Settings();
        System.out.println("1.2 Reading settings from file");
        s.load();
        System.out.println("1.3 Settings loaded successfully!");
    }
}
